home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 6812 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  11.0 KB

  1. Path: news.NetVision.net.il!news
  2. From: Jack <avilev@netvision.net.il>
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: 680X0 -> PPC translator?
  5. Date: Wed, 03 Apr 1996 07:23:56 -0700
  6. Organization: NetVision LTD.
  7. Message-ID: <3162980C.2003@netvision.net.il>
  8. References: <31499F8E.26A9@netvision.net.il> <volker.0fw1@vb.franken.de> <315800D7.1854@sapiens.com> <volker.0g32@vb.franken.de> <315C198B.49C2@netvision.net.il> <volker.0g5w@vb.franken.de>
  9. NNTP-Posting-Host: ts006p2.pop4a.netvision.net.il
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (Win16; I)
  14.  
  15. Volker Barthelmann wrote:
  16. > Jack (avilev@netvision.net.il) wrote:
  17. > : Hi Volker, well i'll try to keep the lines shorter this time
  18. > : so you'll be able to read the text more conveniently and who
  19. > Thanks!
  20. > : know. you might actually be convinced that 680x0 -> PPC is possible. ;-)
  21. > I doubt that. :-)
  22. > : > Perhaps You can perform this analysis. An algorithm can't.
  23. > :
  24. > : why the hell not, if i can understand assembly source code,
  25. > : the machine can understand machine code right?!
  26. > I don't know if You (or any human) can really 'understand' EVERY
  27. > piece of machine code. Of course typical assembly source can be
  28. > understood by humans, because it was written with that in mind.
  29. > you don't have to understand what a program does in order to convert
  30. its code from one instruction set to another. all you look for are
  31. specific things and provided you know the op-codes of the 2 processors
  32. there should be no problem whatsoever.
  33.  
  34. > : > Of course You can have a structure holding all Your variables. Now You pass
  35. > : > the address of this structure to an external function that writes some
  36. > : > values into it and You lost.
  37. > :
  38. > : i don't seem to care about that, get it through your head, i'm NOT
  39. > : going to intervene with what the program does with any memory area,
  40. > : just as long as this memory area is not later being used for code
  41. > Unfortunately You have to know about all other memory areas as well,
  42. > because otherwise You cannot determine what is code and what is data.
  43.  
  44. not necessarily, all static code is inside the program already, all there's 
  45. to do is follow the logic of the program keeping track of what memory areas
  46. are being used AND how. now don't be confused again, you don't need actual
  47. run-time pointer values in order to know how a memory is being used, you use
  48. its 'symbol' ie pointer variable to represent it. if you follow though the 
  49. entire program, never mind its logic, you can know which parts (within the exe) 
  50. are code or data, any part which is jmp'ed to is code otherwise it's data.
  51.  
  52. > Think about: The program writes a value somwhere. Then copies it around,
  53. > shifts it, moves it again etc. and than sometimes it reads it from where
  54. > it is now, loads it in a0 and does a jmp (a0) or so.
  55.  
  56. oh god, how many times will i have to go through this. it doesn't matter
  57. at all because i don't care if that area is jmp'ed directly or indirectly
  58. if i find out that some memory is used as a code area, i go back and trace 
  59. where it was initially assigned and then start following the changes made to
  60. it, making sure to change the size of the area it points to so that the PPC
  61. code will fit nicely. really it's that simple and if you don't believe me
  62. then i'll make my point more concrete for ya, try looking at some assembly
  63. source which does what you just said, YOU can know (if you follow the flow)
  64. the exact area a certain pointer is pointing at, at a given point in the 
  65. program, you can also figure out how it's being used and you can also
  66. figure out what needs to be changed for the PPC translation to work. if you
  67. can do it, bet an algorithm can too.
  68.  
  69. > : execution. then, and only then will i have to turn to all the locations
  70. > : where that pointer could have been assigned and then change the size
  71. > : argument which i already know to the appropriate sizes, once i figure
  72. > : out that the area is code, i will perform a well defined series of actions
  73. > : to resolve ALL dependecies related to that area, including size, write loops etc.
  74. > Well, please define those 'well defined' series of actions.
  75.  
  76. as soon as i find out the pointer is a CODE pointer i do the following:
  77.  
  78. 1) trace back in the program where that pointer was assigned.
  79. 2) decide whether the area it's pointing to is static (meaning within one of
  80. the program's segments) or a dynamic one.
  81. 3) if (2) == dynamic then calculate 'source' code size and look it up withing
  82. one of the arguments just before the call/jmp is made. the argument will
  83. be an immediate or stored in some variable, the point is it's INSIDE the
  84. one of the program's segments and it's a REAL VALUE.
  85. change the size according to the translated code size. (i'm assuming the code
  86. has already been chewed up and spitted out)
  87. 4) is (2) == static then increase the size of the hunk it's located in.
  88. 5) find the last write loop just before the call was made and change the counter's
  89. end value condition, changing the move instruction to move bytes.
  90. 6) go on happily to other parts of the program.
  91.  
  92. HUH, i wrote it, lets see your response to that Volker. flame me good this
  93. time, ok? :-)
  94.  
  95. > : > There are several memory allocating functions or other functions You can't
  96. > : > know anything about.
  97. > :
  98. > : then you take into account all of the various SYSTEM functions which allocate
  99. > : memory (there aren't many of them) and proceed as normal.
  100. > What do You do if a program does an OpenLibrary("some_custom.library",foo);
  101. > and a jsr -some_strange_offset_I've_never_seen_before(a6)?
  102. > This function could call AllocMem. You don't even know what parameters it
  103. > takes etc.
  104.  
  105. AHHHHH, that is where you're wrong (again, teehee), here's that phrase again,
  106. 'keep track', i know i know, this term is without a doubt overused in my articles,
  107. but hey, this is WAR, any means can be used to achieve the target, PPC dominance.
  108. now, if you save your stack status before every call is made, you can know which
  109. parameters on the stack belong to that function. for example if the stack
  110. contained: A,B,C before and now D,E,F are pushed and then there's a call to
  111. some routine then you know D,E,F are its arguments don't you.
  112. bear in mind that the external library is PPC translated already, any 
  113. code-modification tricks it does won't need any changes.
  114. ofcourse, __regarg functions (in C) don't use the stack for all parameters
  115. i know, and some assembly programs like to do register passing of arguments
  116. well, then in that case it's truely more diffilcult but not impossible.
  117. if the call is to some C RTL function, then no sweat, i can go directly to 
  118. the function and actually see how it uses the register in its code and
  119. dicsern the call prototype and make the necessary adjustments. if it's a
  120. DOS library things might get a little complicated, but could be solve by
  121. some educated guess as to what needs to be changed.
  122.  
  123. > : > You would have to adjust EVERYTHING that is in any way dependant on the code
  124. > : > size! How are You going to do this?
  125. > :
  126. > : all you have to look for is where it was allocated and where it is copied,
  127. > : assuming you're copying code that is. quite easily done if you follow the
  128. > : change made to that pointer while 'running' through the program's logic.
  129. > If You write a program that only reads a normal assembly source file that
  130. > is known to copy some piece of code somewhere and Your program can change the
  131. > source to copy one byte more, I'll believe You (and call You god, if You want).
  132.  
  133. well, if i'll have the time and energy i will, but 1st i have to write the analyser
  134. program to do that. that might take some time.
  135.  
  136. > Please tell me more, I'm curious!
  137.  
  138. well, the project analysed the information flow in some organization and tried
  139. to analyse the bottle-necks in that flow which ultimatly caused financial losses
  140. to that company. i won't go into many details of how it's done cuz you'll have to
  141. have background in Automated-data-processing theory in order to comprehand the
  142. terms used and what i'm talking about. suffice to say that by the end, the project
  143. involved an ingenius highly automated and controlled network of computers running
  144. software which dealt specifically with the problems at hand, which increased 
  145. productivity in the short term and profits in the longer term.
  146.  
  147. > Yes, You have. E.g. the allocator could assume that all requests are multiples
  148. > of 1024 and rely on that. Now the original code may have been a multiple
  149. > of 1024, but the PPC-code probably isn't. So when You pass the PPC-code-size
  150. > to the allocator it will go nuts.
  151.  
  152. so what??? the area will later be used in some loop copying the code, right?! it'll 
  153. have to use actuall byte/word count to do that. you look into the allocation 'prototype'
  154. and try to find out that value. if you can't find it, then you're probably right, it
  155. uses some multiple of some size, in that case the minimum multiple it would have to be
  156. is calculated by unit = actual_source_size/num_units_requested; 
  157. then you use that unit size in the calculation of the PPC code size and you're done.
  158. of course there'll be some memory wastes but who cares about that.
  159.  
  160. > : granted, you're right about that not all solutions are clear cut but when it comes
  161. > : to exact sciences such as computer-science then i would disagree, especially
  162. > : since the problem we're dealing with isn't related to any human logic, that
  163. > : field even in computer-science hasn't been fully explored and understood yet.
  164. > : no, the only major problem is self-modification of the program otherwise you
  165. > : translate the code 1:1.
  166. > Still I claim You can't even reliably decide what is code and what is data.
  167. > Even if self-modifying code is forbidden.
  168.  
  169. that's absurd, if a human can follow an assembly source code and can know which
  170. parts are code and which ones are data so can a fucken algorithm.
  171.  
  172. > Assume a program that has some kind of keyfiles. It has n areas that could
  173. > be code or data and Your algorithm has to decide that.
  174. > Assume that the addresses of those areas are in an array adr[n].
  175. > Now the program call the system function Open("env:keyfile",MODE_OLDFILE),
  176. > reads all longwords from the file, adds them up and calls adr[sum%n].
  177. > To know which areas could be called You would have to know all valid
  178. > keyfiles. Of course no algorithm knows them and therefore can't decide what
  179. > is code. qed.
  180.  
  181. if that's your example of a real value, think AGAIN. this can easily be solved
  182. by going through all the various hunks of the program trying to find CODE sections.
  183. when you find a code instruction that 'makes sense' mark the section's entry point.
  184. if somebody else calls it you know it's code for sure, then you translate it.
  185. you go through all such code sections and understand when and where they're being
  186. used making sure to translate only code sections actually being used. if a sequence
  187. of data words reveals code it might actually not be code so you have to defer the
  188. translation until you're sure about it. chances are it's code, if more than 2-3 
  189. instructions exists in sequence that probably is code and can thus be translated.
  190. if it was just random data, then nothing happened, we just randomised it again.
  191. better think harder, now flame me.
  192.  
  193. Avi Lev.
  194.